package com.hzit.controller;

import com.hzit.config.MyConverter;
import com.hzit.service.IStudentService;
import com.hzit.util.PageResult;
import com.hzit.vo.StudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hbxfwf
 * @since 2023-10-20
 */
@Controller
@RequestMapping("/student")
public class StudentController {

	@Autowired
	private IStudentService studentService;

	//1. 查询所有学生
	@GetMapping("/list")
	public String list(Model model){
		//1.1 查询出所有的学生列表
		List<StudentVo> list = studentService.findAll2();
		//1.2 将学生列表放到model中
		model.addAttribute("students",list);
		return "list2";      // 真实的物理路径：/templates/list.html
	}
	//2. 分页查询学生信息
	@GetMapping("/findByPage")
	public String findByPage(@RequestParam(value="page",defaultValue = "1") Integer page,
	                         @RequestParam(value="pageSize",defaultValue = "5") Integer pageSize,
	                         Model model){
		//2.1 开始查询学生信息并分页
		PageResult<StudentVo> pr = studentService.findByPage(page,pageSize);
		//2.2 将分页数据放到model中
		model.addAttribute("pr",pr);
		return "list";
	}


}
